package com.tengju.data.infrastructure.repository.convert;

import com.tengju.data.domain.model.user.StarLevelEnum;
import com.tengju.data.domain.model.user.UserStarFeature;
import com.tengju.data.domain.model.user.UserIdCode;
import com.tengju.data.infrastructure.persistence.mybatis.dataobject.StarUserFeatureMonthDO;

/**
 * @author chenhang
 * @Date 2021/1/22
 */
public class StarFeatureConvert {

    public static UserStarFeature convertSnapshotToModel(StarUserFeatureMonthDO starUserFeatureMonthDO) {
        return new UserStarFeature(
                UserIdCode.of(starUserFeatureMonthDO.getIdCode()),
                StarLevelEnum.parseByStarLevel(starUserFeatureMonthDO.getStarLevel()),
                StarLevelEnum.parseByStarLevel(starUserFeatureMonthDO.getInviteStarLevel()),
                starUserFeatureMonthDO.getTag()
        );
    }

    public static StarUserFeatureMonthDO convertToDo(UserStarFeature userStarFeature, Integer month) {
        StarUserFeatureMonthDO starUserFeatureMonthDO = new StarUserFeatureMonthDO();
        starUserFeatureMonthDO.setIdCode(userStarFeature.getIdCode().getValue());
        starUserFeatureMonthDO.setMonth(month);
        starUserFeatureMonthDO.setStarLevel(userStarFeature.getStarLevel().getCode());
        starUserFeatureMonthDO.setInviteStarLevel(userStarFeature.getInviteStarLevel().getCode());
        starUserFeatureMonthDO.setTag(userStarFeature.getTag());
        return starUserFeatureMonthDO;

    }
}
